<template>
  <div>
    <p>测试</p>
    <p>新建测试任务</p>
    <!-- 选择已经测试好的任务 -->
    <div class="select">
      <span>选择已经测试好的任务</span>
      <el-select
        v-model="taskAddParam.frontTask"
        placeholder="请选择已测试好的任务"
      >
        <el-option
          v-for="item in testTask"
          :key="item.value"
          :label="item.taskName"
          :value="item.id"
        >
        </el-option>
      </el-select>
    </div>
    <!-- 选择报表数据集 -->
    <div class="select">
      <span>选择报表数据集</span>
      <el-select v-model="taskAddParam.assetId" placeholder="请选择">
        <el-option
          v-for="item in asset"
          :key="item.id"
          :label="item.assetName"
          :value="item.id"
        >
        </el-option>
      </el-select>
    </div>
    <!-- 新建任务名 -->
    <div class="select">
      <span>任务名</span>
      <el-input
        v-model="taskAddParam.taskName"
        size="medium"
        clearable
        placeholder="请输入新建报表任务名"
      ></el-input>
    </div>

    <!-- 自定义参数 -->
    <div>
      <span>自定义参数</span>
      <el-input
        v-model="taskAddParam.taskParam"
        size="medium"
        clearable
        placeholder="请输入自定义参数"
      ></el-input>
    </div>

    <!-- 启动报表 -->
    <div class="btn">
      <el-button type="primary" plain @click="creattask()">启动报表</el-button>
    </div>
    <div class="css">
      <!-- <router-view></router-view> -->
    </div>
  </div>
</template>
<script>
import { baseUrls } from "@/main.js";
export default {
  data() {
    return {
      testTask: [],
      trainingdata: [],
      asset: [],
      taskAddParam: {
        assetId: "",
        frontTask: "",
        taskName: "",
        taskParam: "",
        taskType: 2,
      },
    };
  },
  methods: {
    // 提交创建测试任务
    async creattask() {
      const res = await this.$http
        .post(`${baseUrls.base2}/task`, this.taskAddParam)
        .then((res) => {
          console.log(this.taskAddParam);
          console.log(res.data);
          if (res.data.status == 200) {
            this.$message.success("创建报表任务成功");
          } else {
            this.$message.error(res.data.msg);
          }
        });
    },
    //选择已经测试好的任务
    async chooseTestTaskId() {
      const res = await this.$http
        .get(`${baseUrls.base2}/task/all`, {
          params: { taskState: 2, taskType: 1 },
        })
        .then((res) => {
          // console.log(res.data);
          this.testTask = res.data.data;
          console.log(this.testTask);
        });
    },
    //选择报表数据集
    async chooseAsset() {
      const res = await this.$http
        .get(`${baseUrls.base2}/asset/all`)
        .then((res) => {
          this.asset = res.data.data;
        });
    },
  },
  created() {
    this.chooseTestTaskId(), this.chooseAsset();
  },
};
</script>
<style scoped>
.select,
.btn {
  margin: 30px 0;
}
.el-input {
  width: 20vw;
}
span {
  display: inline-block;
  margin-right: 20px;
}
</style>
